﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DAO_ADMIN;
using PTTK19.BUS;
using System.Data.SqlClient;
namespace PTTK19.DB
{
    public class DBMonAn
    {
        //Lay danh sach mon an
        public static DataTable getListMonAn()
        {
            //DBMS dbms = new DBMS();
            string procname = "sp_LayDanhSachMonAn";
            DataTable dt = DataProvider.SelectStoreProcedure(procname);
            return dt;
        }
        //Cap nhat mon an
        public static void CapNhatMonAn(int _MaMonAn, string _TenMonAn, string _CachCheBien)
        {
            List<SqlParameter> parr = new List<SqlParameter>();
            string procname = "sp_CapNhatMonAn";
            parr.Add(new SqlParameter("@MaMonAn", _MaMonAn));
            parr.Add(new SqlParameter("@TenMonAn", _TenMonAn));
            parr.Add(new SqlParameter("@CachCheBien", _CachCheBien));
            DataProvider.NonqueryProc(procname, parr);
        }
        //Them mon an
        public static void ThemMonAn(string _TenMonAn, string _CachCheBien)
        {
            List<SqlParameter> parr = new List<SqlParameter>();
            string procname = "sp_ThemMonAn";
            parr.Add(new SqlParameter("@TenMonAn", _TenMonAn));
            parr.Add(new SqlParameter("@CachCheBien", _CachCheBien));
            DataProvider.NonqueryProc(procname, parr);
        }
        //Huy mon an
        public static void HuyMonAn(int _MaMonAn)
        {
            List<SqlParameter> parr = new List<SqlParameter>();
            string procname = "sp_HuyMonAn";
            parr.Add(new SqlParameter("@MaMonAn", _MaMonAn));
            DataProvider.NonqueryProc(procname, parr);
        }

        internal static DataTable ChiTietMonAn(int _curID)
        {
            List<SqlParameter> parr = new List<SqlParameter>();
            string procname = "sp_ChiTietMonAnTheoThucDon";
            parr.Add(new SqlParameter("@MaThucDon", _curID));
            DataTable dt = DataProvider.SelectStoreProcedure(procname,parr);
            return dt;
        }

        internal static DataTable GetList()
        {
            string procname = "sp_LayDanhSachMonAnRG";
            DataTable dt = DataProvider.SelectStoreProcedure(procname);
            return dt;
        }

        internal static DataTable GetList(int ID)
        {
            List<SqlParameter> parr = new List<SqlParameter>();
            string procname = "sp_DSMonAnTheoThucDon";
            parr.Add(new SqlParameter("@MaThucDon", ID));
            DataTable dt = DataProvider.SelectStoreProcedure(procname, parr);
            return dt;
        }

        internal static DataTable LayMonAnTheoNgay(DateTime ngay)
        {
            List<SqlParameter> parr = new List<SqlParameter>();
            string procname = "ThucDonTheoNgay";
            parr.Add(new SqlParameter("@ngaylap", ngay));
            DataTable dt = DataProvider.SelectStoreProcedure(procname, parr);
            return dt;
        }
        
        internal static DataTable ThongKeMonAnTheoThang(string thang)
        {
            string[] ngaythangdulieu = { "0", "31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31" };
            int tam = int.Parse(thang.Substring(0, thang.IndexOf('/')));
            string startdate = "01/" + thang;
            string enddate = ngaythangdulieu[tam] + "/" + thang;
            DateTime ngaydau = Convert.ToDateTime(startdate);
            DateTime ngaycuoi = Convert.ToDateTime(enddate);
            List<SqlParameter> parr = new List<SqlParameter>();
            string procname = "ThongKeMonAnTheoThang";
            parr.Add(new SqlParameter("@ngaydau", ngaydau));
            parr.Add(new SqlParameter("@ngaycuoi", ngaycuoi));

            DataTable dt = DataProvider.SelectStoreProcedure(procname, parr);
            return dt;
        }
    }
}
